<?php

namespace App\Controller\Router;

abstract class Route implements Parser
{
    protected $_moduleKey     = 'module';
    protected $_controllerKey = 'controller';
    protected $_actionKey     = 'action';

    protected $_defaults;
    protected $_parseMap;

    protected $_request;

    public function __construct(array $defaults = array(), $request = null)
    {
        $this->_defaults = $defaults;
        $this->_request  = $request;
    }

    //abstract public function match($path);

    /* @todo: 此方法有待考证 */
    public function preDispatch(){}

    public function dispatch()
    {
        $module     = $this->_parseMap[$this->_moduleKey];
        $controller = $this->_parseMap[$this->_controllerKey];
        $action     = $this->_parseMap[$this->_actionKey];
        unset($this->_parseMap[$this->_moduleKey], $this->_parseMap[$this->_controllerKey], $this->_parseMap[$this->_actionKey]);

        $this->_request->setParams($this->_parseMap);

        $namespace  = PROJECT_NAME.'\\modules\\'.$module.'\\controller';
        $control = $namespace.'\\'.$controller;
        $c = new $control();
        //$c->request = $this->_request;
        $c->{$action.'Action'}();
            //self::exceptionHandler($e);
    }
}
